/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.intercoop_abroad.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.intercoop_abroad.entity.TbIntercoopAbroad;
import com.thinkgem.jeesite.modules.intercoop_abroad.service.TbIntercoopAbroadService;

/**
 * 学生赴境外学习交流Controller
 * @author hang
 * @version 2017-01-14
 */
@Controller
@RequestMapping(value = "${adminPath}/intercoop_abroad/tbIntercoopAbroad")
public class TbIntercoopAbroadController extends BaseController {

	@Autowired
	private TbIntercoopAbroadService tbIntercoopAbroadService;
	
	@ModelAttribute
	public TbIntercoopAbroad get(@RequestParam(required=false) String id) {
		TbIntercoopAbroad entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbIntercoopAbroadService.get(id);
		}
		if (entity == null){
			entity = new TbIntercoopAbroad();
		}
		return entity;
	}
	
	@RequiresPermissions("intercoop_abroad:tbIntercoopAbroad:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbIntercoopAbroad tbIntercoopAbroad, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbIntercoopAbroad> page = tbIntercoopAbroadService.findPage(new Page<TbIntercoopAbroad>(request, response), tbIntercoopAbroad); 
		model.addAttribute("page", page);
		return "modules/intercoop_abroad/tbIntercoopAbroadList";
	}

	@RequiresPermissions("intercoop_abroad:tbIntercoopAbroad:view")
	@RequestMapping(value = "form")
	public String form(TbIntercoopAbroad tbIntercoopAbroad, Model model) {
		model.addAttribute("tbIntercoopAbroad", tbIntercoopAbroad);
		return "modules/intercoop_abroad/tbIntercoopAbroadForm";
	}

	@RequiresPermissions("intercoop_abroad:tbIntercoopAbroad:edit")
	@RequestMapping(value = "save")
	public String save(TbIntercoopAbroad tbIntercoopAbroad, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbIntercoopAbroad)){
			return form(tbIntercoopAbroad, model);
		}
		tbIntercoopAbroadService.save(tbIntercoopAbroad);
		addMessage(redirectAttributes, "保存学生赴境外学习交流成功");
		return "redirect:"+Global.getAdminPath()+"/intercoop_abroad/tbIntercoopAbroad/?repage";
	}
	
	@RequiresPermissions("intercoop_abroad:tbIntercoopAbroad:edit")
	@RequestMapping(value = "delete")
	public String delete(TbIntercoopAbroad tbIntercoopAbroad, RedirectAttributes redirectAttributes) {
		tbIntercoopAbroadService.delete(tbIntercoopAbroad);
		addMessage(redirectAttributes, "删除学生赴境外学习交流成功");
		return "redirect:"+Global.getAdminPath()+"/intercoop_abroad/tbIntercoopAbroad/?repage";
	}

}